package com.qf.homework.controller;

import com.qf.homework.model.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.*;
import java.util.List;
import java.util.Random;

@Controller//代表当前类是一个springMVC框架中的后端控制器类
@RequestMapping
public class RollCallServlet {
    @Autowired
    private UserService userService;

    @RequestMapping("/findName")
    public String findName(HttpServletRequest req) {
        List<String> name = userService.findName();
        Integer index = new Random().nextInt(name.size());
        req.setAttribute("name", name.get(index));
        return "forward:/view/rollcall.jsp";
    }
}
